<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../js/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
var count = 1;
$(document).ready(function(){
        $("#btn1").click(function(){
        	  ++count;
        	  alert("count=" + count)
        	  window.location.reload(true);
        });
        
        // chrome下可以工作
        $("#btn2").click(function(){
        	//window.opener.callback(count);
      		 if(parent.window.opener != null && !parent.window.opener.closed){
      				parent.window.opener.callback(count);
    		 }else{
    			 alert("parent opener is null");
    		 }
      		 
        	window.close();
        });
        
        // IE下可以工作，chrome不可以
        $(window).unload(function(){
        	//alert("unload count=" + count);
        });
        
        // IE下可以工作，chrome不可以
        $(window).on('unload', function(){
        	alert("unload count=" + count);
 			//window.opener.callback(count);
        });
     
        // IE， chrome都不可以
        $(window).beforeunload(function(){
        	//alert('asdf');
        	return "jquery onbeforeunload is work";
        });

});

	// chrome / IE 下都可以工作
	window.onbeforeunload = function(){
		//window.opener.callback(count);
		return "onbeforeunload is work";
		}
	
</script>
</head>
<body>
<button id="btn1" type="button">refresh</button>
<button id="btn2" type="button" >close</button>

<script type="text/javascript">

// 
function closeWin(){
	
//chrome下需要用parent.window.opener, 并且不能在文件系统中直接打开html页面，需要放到服务器中。file和http协议处理起来不一样
/* 		 if(parent.window.opener != null && ! parent.window.opener){
				parent.window.opener.callback(count);
		 }else{
			 alert("parent opener is null");
		 }
		 
		 if(window.opener != null && ! window.opener){
			window.opener.callback(count);
		 }else{
			 alert("opener is null");
		 }
		 
		 if(window.parent  != null){
			 alert("parent is not null");
			 if(window.parent.callback){
				 window.parent.callback(count);				 
			 }else{
				 alert("window.parent.callback is null");
			 }

		 }else{
			 alert("parent is null");
		 }
		 
		 if(window.opener.opener != null){
			 window.opener.opener.callback(count);
		 }else{
			 alert("window.opener.opener callback is null");
		 } */
		 

	    try{
	        if(parent.window.opener != null && !parent.window.opener.closed)
	        {
	          parent.window.opener.callback(count);
	        }

	    }catch(e){ alert(e.description);}       
	
		 
 	window.close();
}
</script>
</body>

</html>